public class Leet224 {
    public static void main(String[] args) {
        Leet224 l = new Leet224();
        System.out.println(l.calculate("-2+ 1"));
    }
    public int calculate(String s) {
        StringBuilder sb = new StringBuilder();
        for(char a :s.toCharArray()){
            if (a=='('||a==')'||a==' ')
                continue;
            sb.append(a);
        }
        String str = sb.toString();
        int num = 0;
        sb = new StringBuilder();
        char ai = '+';
        if (str.charAt(0)=='-'){
            ai = '-';
            str = str.substring(1);
        }
        System.out.println(str);
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i)!='+'&&str.charAt(i)!='-')
                sb.append(str.charAt(i));
            else {
                int t = Integer.parseInt(sb.toString());
                sb = new StringBuilder();
                if (ai == '+')
                    num+=t;
                if (ai == '-')
                    num-=t;
                if (str.charAt(i)=='+')
                    ai = '+';
                if (str.charAt(i)=='-')
                    ai = '-';
            }
        }
        if (ai == '+')
            num+=Integer.parseInt(sb.toString());
        if (ai == '-')
            num-=Integer.parseInt(sb.toString());
        return num;
    }
}
